import requests
from DrissionPage import Chromium, ChromiumPage

tab = Chromium().latest_tab

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
    'referrer': 'https://www.kuaishou.com/',
}
username = "d2356162166"
password = "l7zee1jn"
IP = "36.156.102.17:30154"
# 代理
proxies = {
    "http": f"http://{username}:{password}@{IP}",
    "https": f"http://{username}:{password}@{IP}",
}

tab.listen.start('graphql')

tab.get('https://www.kuaishou.com/profile/3xk46q9cdnvgife')

res_list = tab.listen.wait(count=6)
for res in res_list:
    try:
        res = res.response.body
        print(res)
        video_list = res['data']['visionProfilePhotoList']['feeds']
        num = 0
        for video in video_list:
            num += 1
            video_title = video['photo']['caption']
            author_id = video['author']['id']
            video_url = video['photo']['photoH265Url']
            print(video_title, author_id, video_url)
            with open(f'{num}.mp4', 'wb') as f:
                f.write(requests.get(video_url,proxies=proxies,headers=headers).content)
            if num == 2:
                break

    except Exception as e:
        print(e)
